#ifndef __NUMBER_H
#define __NUMBER_H

#include <set>
#include <string>

using namespace std;

/** A semi-stateful class for storing a long integer.
 * Supports subtotals during parsing, and an arbitrary set of string flags
 * to be used during the parsing. Could actually be part of Parser.
 *
 * <p>For comparison purposes, a number can be defined as invalid, to be
 * different from anything that is valid.</p>
 */
class Number {
  /** Friends.
   * The NumRule class intensively modifies the fields of this class.
   */
  friend class NumRule;

  private:
    /** Subtotal and value.
     * These together add up to the actual mathematical value of the Number.
     */
    long subtotal, value;
    /** Set of flags.
     * These flags are used / manipulated by the parser.
     */
    set<string> flags;
    /** Before first literal parsed.
     * This field is true if parsing is before first literal.
     * 
     * @see #isFirst()
     */
    bool first;
    /** An artificial toggle for invalid numbers. */
    bool valid;

    /** A strictly forbidden constructor for defining invalid numbers. */
    Number(bool v);

  public:
    /** Generic constructor. 
     * Sets initial value to specified and no flags. 
     */
    Number(long l = 0);

    /** Get the total value of the number.
     *
     * @return the value of the number, as parsed so far.
     */
    const long getValue();

    /** Tell if parsing for this number has been started.
     *
     * @return true if parsing is before first literal.
     */
    const bool isFirst();

    /** Standard operators to compare with another Number. */
    bool operator==(Number other);
    /** Standard operators to compare with another Number. */
    bool operator!=(Number other);

    /** An artificial invalid number. 
     * Similar to NaN, it is used to determine if the number has been 
     * initialised yet.
     */
    const static Number &NOTANUMBER;
};

#endif
